# input is in multinomial.csv
# output is in multinomial.out
library( nnet )

setwd( "D:/AAAI ConcSDP Code/concurrent-value-iteration/" );

data <- read.csv("multinomial.csv", header=TRUE);
data$action <- as.factor( data$action )

named <- names(data )

named <- subset( named, named !="action" )

len <- length( named )

form <- as.formula ( paste( "action ~ ", paste( named, collapse="+") ) )

mod <- multinom( form , data = data )

haz <- levels(data$action)
haz <- subset( haz, haz != 0 )
haz <- as.integer( haz )

mat <- matrix(nrow=3, ncol=len+1, data=0)

coefs <- as.matrix( coef(mod) )

nparams <- dim( coefs )[1]

count <- 1
for( i in haz ){
  mat[i,] <- coefs[ count , ]
  count <- count+1
}

write.csv( mat , file="multinomial.out")